﻿Public Class nuevo_grupo
    Dim id As String
    Dim qry As String
    Dim flag As Boolean = False
    Dim ceditar As String
    Dim dataset As New DataSet
    Public Sub setid(ByVal id As Integer, ByVal ceditar As String)
        Me.id = id
        Me.ceditar = ceditar
        flag = True
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub

    Private Sub btn_aceptar_Click(sender As System.Object, e As System.EventArgs) Handles btn_aceptar.Click
        If ValidarVacio(Me, Me.ErrorProvider1) = True Then
            qry = "insert into grupos values('" & TextBox1.Text & "','" & RichTextBox1.Text & "')"
            ' MsgBox(qry)
            EjecutaConsulta(qry)
            'registro movimiento
            registro("agregar", login.usuario.id, main.modulo.grupos)
            Me.Close()
            man_grupos.actualizar()
        End If

    End Sub

    Private Sub nuevo_grupo_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.Icon = (My.Resources.favicon)
        If (flag) Then
            Me.Text = "Editar Grupo"
            subtitulo.Text = "Editar Grupo"
            btn_aceptar.Hide()
            btn_editar.Show()
            'carga
            Consulta(ceditar, dataset)
            TextBox1.Text = dataset.Tables("data").Rows(0)(1)
            RichTextBox1.Text = dataset.Tables("data").Rows(0)(2)
        Else
            btn_editar.Hide()
        End If
    End Sub

    Private Sub btn_editar_Click(sender As System.Object, e As System.EventArgs) Handles btn_editar.Click
        If ValidarVacio(Me, Me.ErrorProvider1) = True Then
            qry = "update grupos set grup_nombre='" & TextBox1.Text & "',grup_descripcion='" & RichTextBox1.Text & "' where grup_id='" & id & "'"
            EjecutaConsulta(qry)
            'registro movimiento
            registro("modificar", login.usuario.id, main.modulo.grupos)
            Me.Close()
            man_grupos.actualizar()

        End If
    End Sub

    Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        ValidarCaracteresEspeciales(e)
    End Sub

    Private Sub RichTextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles RichTextBox1.KeyPress
        ValidarCaracteresEspeciales(e)
    End Sub
End Class